package com.njupt.swg.threadstudyjimin.item05.publish;

import com.njupt.swg.threadstudyjimin.annotation.NotThreadSafe;
import lombok.extern.slf4j.Slf4j;

import java.util.Arrays;

@Slf4j
@NotThreadSafe
public class UnSafePublish {
    private String[] states = {"a","b","c"};

    //发布类的域states
    //在类的外面线程都可以访问到这个域并且进行修改，所以这是不安全的发布方式
    public String[] getStates(){
        return states;
    }

    public static void main(String[] args) {

        UnSafePublish unSafePublish = new UnSafePublish();
        log.info("1.--{}", Arrays.toString(unSafePublish.getStates()));

        //拿到引用之後就可以直接修改，其他线程也可以拿到这个引用进行修改
        unSafePublish.getStates()[0] = "d";
        log.info("2.--{}",Arrays.toString(unSafePublish.getStates()));
    }
}
